<%@ page language="java" import="com.alibaba.fastjson.JSONArray" pageEncoding="UTF-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.zhlx.duss.utils.SapUtil" %>
<%--流程退回调用QMS接口--%>
<%
    String requestid = "3972973";
    String tablename = "formtable_main_4109";
    out.print(">>>>>WeaCzgdlcAction>>>>>requestid=" + requestid+ "<br/>");
    try {
        RecordSet rs = new RecordSet();
        SapUtil sapUtil = new SapUtil();
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        rs.next();
        JSONArray retrunList = new JSONArray();
        String mainid = Util.null2String(rs.getString("id"));
        rs.executeQuery("select * from " + tablename + "_dt1 where mainid=? and nvl(ksykcsl,0)<sl", mainid);
        int counts = rs.getCounts();
        int scusscount = 0;
        int count = 1;
        while (rs.next()) {
            JSONObject retrunJson = new JSONObject();
            String id = Util.null2String(rs.getString("id"));
            int sl = Util.getIntValue(rs.getString("sl"), 0);
            String ljbh = Util.null2String(rs.getString("ljbh"));
            JSONObject dataJson = new JSONObject();
            JSONObject headerJson = new JSONObject();
            //物料号
            headerJson.put("MATNR", ljbh);
            //批次号
            headerJson.put("CHARG", Util.null2String(rs.getString("pcbh")));
            //工厂
            headerJson.put("WERKS", Util.null2String(rs.getString("gc")));
            //库存地点
            headerJson.put("LGORT", Util.null2String(rs.getString("shfhkcdd")));
            //特殊库存标识
            headerJson.put("SOBKZ", Util.null2String(rs.getString("tskcbs")));
            //特殊库存编号
            headerJson.put("LIFNR", Util.null2String(rs.getString("tskcbh")));
            //评估类型
            headerJson.put("BWTAR", Util.null2String(rs.getString("pglx")));
            dataJson.put("HEADER", headerJson);
            out.println(">>>>>WeaWlzcSapAction>>>>>dataJson=" + dataJson+"<br/>");
            JSONObject resultJson = sapUtil.handleOKHttpRequestNotLog("MM088", dataJson);
            out.println(">>>>>WeaWlzcSapAction>>>>>resultJson=" + resultJson+"<br/>");
            String code = Util.null2String(resultJson.getString("code"));
            if ("success".equals(code)) {
                String output = Util.null2String(resultJson.getString("OUTPUT"));
                JSONObject outputJson = JSONObject.parseObject(output);
                String msgType = outputJson.getString("MSG_TYPE");
                if ("S".equals(msgType)) {
                    String dataStr = outputJson.getString("DATA");
                    JSONObject returnDataJson = JSONObject.parseObject(dataStr);
                    JSONArray returnList = JSONArray.parseArray(returnDataJson.getString("RETURN"));
                    for (int i = 0; i < returnList.size(); i++) {
                        JSONObject returnJson = returnList.getJSONObject(i);
                        out.println(">>>>>WeaWlzcSapAction>>>>>Json=" + returnJson+"<br/>");
                        double fxzkz = Util.getDoubleValue(returnJson.getString("FXZKZ"), 0);
                       // out.println(">>>>>WeaWlzcSapAction>>>>>fxzkz=" + fxzkz+"<br/>");
                        rs.executeUpdate("update " + tablename + "_dt1 set ksykcsl=? where id=?", fxzkz, id);
                        if (fxzkz >= sl) {
                            scusscount++;
                        } else {
                            retrunJson.put("明细序号"+count, ljbh);
                        }
                    }
                } else {
                    String message = outputJson.getString("MSG_TEXT");
                    retrunJson.put("明细序号"+count, message);
                }
            }
            retrunList.add(retrunJson);
            count++;
        }
        if (scusscount != counts) {
            rs.executeUpdate("update " + tablename + " set jkcljg='"+retrunList.toJSONString()+"' where requestid=?", requestid);
        }else {
            rs.executeUpdate("update " + tablename + " set jkcljg='' where requestid=?", requestid);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.println(">>>>>测试接口异常！！！");
    }

%>




